package com.food.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.food.dao.service.ProductService;
import com.food.model.Product;

/**
 * Servlet implementation class ProductPayServlet
 */
@WebServlet("/ProductPayServlet")
public class ProductPayServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ProductPayServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=utf-8");
		
		/* 取得參數 */
		//String action = request.getParameter("action");
		String pid = request.getParameter("pid");
		
		/* 印出結果 */
		//System.out.println("action:" + action);
		System.out.println("pid:" + pid);
		/* 叫用服務 */
		ProductService prodsv = new ProductService();

	
		
		/* 當 action=buy_product */
		//if ("buy_product".equals(action)) {
			
			
			/*從服務取得 物件集合*/
			Product buyProduct = prodsv.findOneProduct(Integer.parseInt(pid));
			
			
			/*設定傳出物件名稱:products_Det 內容:xxx*/
		
			
			request.setAttribute("products_Pay", buyProduct);
			
//			HttpSession session = request.getSession();
//			session.setAttribute("products_Pay_Session", xx);
			
			
			RequestDispatcher rd = request
					.getRequestDispatcher("/shopping/shoppingPay.jsp");
			rd.forward(request, response);
			return;
		//}
		

	}

}
